{extend name="public/base"/}
{block name="style"}
<script type="text/javascript" src="/public/lboyue/m/sitejs/book.js?v=20181123"></script>
<script type="text/javascript">

    $(document).ready(function () {


        $('.moreIco').click(function () {

            if($(this).hasClass('closeIco')){

                $('#header').removeClass('app_headerFixed2');
                $(this).removeClass('closeIco');
                $('.app_header_second').hide();
                $('.app_meskSection').hide();

            }else{

                $('#header').addClass('app_headerFixed2');
                $(this).addClass('closeIco');
                $('.app_header_second').show();
                $('.app_meskSection').show();
            }



        })

        $('body').on('click','.app_meskSection',function () {
            $('.app_header_second').hide();
            $('.app_meskSection').hide();
            $('#header').removeClass('app_headerFixed2');
            $('.moreIco').removeClass('closeIco');
        })
    })

</script>
{/block}
{block name="body"}
<div class="app_goBackToTop"></div>
<div class="app_meskSection"></div>

<div class="container">

    <div class="app_header_section2  app_scrollerHeader" id="header">
        <div class="app_header_detail2">
            <div class="app_header_back"></div>
            <div class="app_header_h1">
                书架                <a href="/personal/bookcase"> <i class="shujiaIco"></i></a>
                <i class="moreIco"></i>
            </div>
        </div>
		{include file="public/dropnav" /}
	    </div>



    <div class="app_body">
        
		<div class="app_topTabBlock">
			<span class="public_AddFloatLeft  leftFont" id="bookNum">共0本书</span>
			<span class="public_AddFloatRight rightButton" id="success" style="display: none;">完成</span>
			<span class="public_AddFloatRight rightButton" id="allDelete" style="display: none;">全部删除</span>
			<span class="public_AddFloatRight rightButton" id="administration">管理</span>
		</div>
		<div class="app_listBlock app_deleteMargin" id="content" style="min-height: 7.5rem">
			<div class="app_listBlock_con">
				<ul class="app_deletePaddingBottom" id="list">
					
				</ul>
			</div>

		</div>
		<div class="app_noBookDataBlock" id="noData">
			书架空空如也, 你看过的书会出现在这里,
			去书城挑本好书看吧
			<div class="app_listBlockButton"><button onclick="javascript: window.location.href='/top/'">去排行榜找本好书</button></div>
		</div>
		{block name="include"}{include file="public:footer" /}{/block}
    </div>
</div>


{/block}
{block name="script"}
   <script type="text/javascript" src="/public/lboyue/m/js/libs/jquerybase64.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/js/libs/jquery.json-2.4.min.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/js/libs/layer/layer.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/js/libs/jquery.cookie.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/sitejs/book.js?v=20180507"></script>
    <script type="text/javascript" >
        var domain = "{$Think.config.web_pc_url|str_replace="http://www","",###}";
		var auto_go = '{$focus}';
        var DeveloperMode = "";
        $(document).ready(function () {


            /** 计算总共有多少本书在列表中 */
            $('#bookNum').html('共有'+$('#list li').length+'本书');

            /** 删除书架 */
            $('#list').on('click','.deleteBlock',function () {
                var totalbook = $('#list li').length;
                if (totalbook == 0) {
                    malerr("没有可删除的书籍");
                    return "";
                }
                var delbookid = $(this).attr("bookid");
                var delchapterid = $(this).attr("chapterid");
                var obj = $(this);
                layer.open({
                    content: "是否删除书籍？",
                    btn: ["删除" , '取消'],
                    skin: 'footer',
                    yes: function(index){

                        var re = bookselfdata(delbookid, delchapterid, 3, domain);
                        result = parseInt(re);
                        switch (result) {
                            case 1:
                                malerr("书籍删除成功");
                                obj.parent().remove();
                                $('#bookNum').html('共有'+$('#list li').length+'本书');
                                if($('#list li').length==0){
                                    $("#noData").show();
									$("content").hide();
                                }
                                break;
                            case 0:
                                malerr("书籍删除失败");
                                break;
                            case 999:
                                malerr("没有可删除书籍");
                                break;
                        }
                    }
                });
            });

            /** 全部删除 */
            $('#allDelete').click(function () {
                if ($('#list li').length < 1) {
                    malerr("没有可删除的书籍");
                    return "";
                }
                layer.open({
                    content: "是否全部删除书籍？",
                    btn: ["删除" , '取消'],
                    skin: 'footer',
                    yes: function(index){
                        var re = bookselfdata(0, 0, 4, domain);
                        result = parseInt(re);
                        result = parseInt(re);

                        switch (result) {
                            case 1:
                                malerr("书籍删除成功");
                                $('#list').html('');
                                $('#bookNum').html('共有'+$('#list li').length+'本书');
                                if($('#list li').length==0){
                                    $("#noData").show();
									$("content").hide();
                                }
                                break;
                            case 0:
                                malerr("书籍删除失败");
                                break;
                            case 999:
                                malerr("没有可删除书籍");
                                break;
                        }
                    }
                });
            });



            /** 点击完成按钮 */
            $('#success').click(function () {

                $('#administration').show();
                $('#allDelete').hide();
                $(this).hide();

                $('#list .rightJustTime').show();
                $('#list .deleteBlock').hide();
            })

            /** 点击管理 */
            $('#administration').click(function () {

                $(this).hide();
                $('#allDelete').show();
                $('#success').show();

                $('#list .rightJustTime').hide();
                $('#list .deleteBlock').show();

            })

			$.ajax({
                url      : "/api/history/bookshelf",
                type     : "POST",
                dataType : "json",
                data     : {},
                success  : function (re) {
                    var code = re.code;
                    switch (code)
                    {
                        case 1:
                            var data = re.data;
                            var html = "";
                            for (var i=0; i < data.length; i++) {

								if( auto_go == 1 &&  i ==0){
									location.href = '/chapter/read/'+data[i].id+'/'+data[i].chapterid+'/';
									return false;
								}
                                html +='<li class="li2">							<a href="/chapter/read/'+data[i].id+'/'+data[i].chapterid+'/" style="width:85%">								<div class="leftImage2"><img src="'+data[i].cover+'" onerror="javascript:this.src=\'/public/novel/images/default.jpg\';"/></div>								<div class="rightBlock">									<span class="rightBlock_title">'+data[i].title+'</span>									<span class="rightBlock_name">'+data[i].author+' | '+data[i].category+'</span>									<span class="rightBlock_con  rightBlock_con2">										  <span class="con">											  <span class="spanLi">更新至'+data[i].lastvolume+'</span>											  <span class="spanLi">阅读至'+data[i].chaptername+'</span>										  </span>										  <span class="rightJustTime">'+data[i].updatetime+'</span>									 </span>								</div>							</a>							<span class="deleteBlock" bookid="'+data[i].id+'" chapterid="0"></span>						</li> ';
                            }
                            $("#list").html(html);
							$("#noData").hide();
							$('#bookNum').html('共有'+$('#list li').length+'本书');
                            break;
                        default:
                            malert(re.msg, 1200, 2);
                            break;
                    }
                },
                error    : function () {
					$("#content").hide();
                    $("#noData").show();
                    return "";
                }
            });


        })


        function malerr(message, time) {
            if (time == undefined) {
                time = 2;
            }
            layer.open({
                content: message,
                time: time,
                skin: 'msg',
            });
        }

    </script>
{/block}


